<template>
    <div class="CollectMoney contract-detial-page contract-inquiry-detial">
        <Card>
            <div class="common_br">
                <h2 class="common_title">日志 <span style="font-weight: 400;font-size: 14px;padding-left: 16px;">{{pageParams.contractNo}}</span>
                </h2>
                <div class="common_content">
                    <Table width="100%" :columns="tableHead" :data="tableData"
                           :loading="loading">
                        <!-- 业务类型 -->
                        <template slot-scope="{ row }" slot="contractBusiness">
                            <span>{{getTitle('contractBusiness',row.contractBusiness)}}</span>
                        </template>
                        <!-- 来源 -->
                        <template slot-scope="{ row }" slot="businessSource">
                            <span>{{getTitle('businessSource',row.businessSource)}}</span>
                        </template>
                    </Table>
                </div>
            </div>
        </Card>
    </div>
</template>

<script>
    import {getDictDataList, getTitleFromDataDict} from "_p/basic/assets/contract/js/utils";
    import {logDetail} from "_p/basic/api/contract/contract-detail-inquiry";

    export default {
        // 合同明细详情
        name: "ContractInquiryDetial",
        data() {
            return {
                pageNo: 1,
                loading: false,
                isSP: false,
                pageParams: null,
                contractNo: "",
                openPanel: [],
                // 放款模式(loanModel) 变更类型  变更主体(PersonRoleType)
                dictArr: ["businessSource", "contractBusiness"],
                dataDict: {},
                tableHead: [
                    {
                        title: "业务类型",
                        key: "contractBusiness",
                        slot: "contractBusiness",
                        minWidth: 150,
                    },
                    {
                        title: "案件编号",
                        key: "caseNo",
                        minWidth: 200,
                        render: (h, params) => {
                            return h('span', {
                                // props: {
                                //     content: params.row.caseNo,
                                //     transfer: true
                                // }
                            }, [h('a', {
                                class: 'applyNo',
                                style: {
                                    width: (params.column._width - 38) + 'px',
                                },
                                on: {
                                    click: () => {
                                        this.showContractDetail(params.row)
                                    }
                                }
                            }, params.row.caseNo)])
                        }
                    },
                    {
                        title: "来源",
                        key: "businessSource",
                        slot: "businessSource",
                        minWidth: 150,
                    },
                    {
                        title: "申请时间",
                        key: "applyTime",
                        minWidth: 150,
                    },
                    {
                        title: "结束时间",
                        key: "endDate",
                        minWidth: 150,
                    }
                ],
                tableData: []
            };
        },
        computed: {},
        created() {
            this.getParams();
        },
        mounted() {
            this.init();
        },
        methods: {
            init() {
                this.getDetial();
                this.getDictDataList();
            },
            // 获取初始数据
            getParams() {
                const pageParams = this.afs.getPageParams(this);
                console.log("getPageParams", pageParams);
                this.pageParams = pageParams;
                this.contractNo = pageParams.contractNo;
            },
            // 数据字典
            getDictDataList() {
                getDictDataList(this.dictArr).then(res => {
                    console.log("getDictDataList(this.dicttArr)", res);
                    this.dataDict = res;
                });
            },
            getDetial() {
                logDetail(this.contractNo).then(res => {
                    if (res.code === "0000" && res.data) {
                        this.tableData = res.data
                    }
                })
            },
            getTitle(type, val) {
                let data = this.dataDict[type + "Dict"] || [];
                return getTitleFromDataDict(data, val);
            },
            showContractDetail(params) {
                console.log(111111111111, params)
                switch (params.contractBusiness) {
                    case "cancelContract": // 合同取消
                        this.cancelContractPage(params)
                        break;
                    case "advanceSettle": // 提前结清
                        this.advanceSettlePage(params)
                        break;
                    case "extension": // 展期
                        this.extensionPage(params)
                        break;
                    case "insurance": // 保险业务
                        this.insurancePage(params)
                        break;
                    case "corporateSettlementRent": // 对公结算
                        this.corporateTransferPage(params)
                        break;
                    case "corporateSettlementPrepayment": // 对公结算
                        this.corporateTransferPage(params)
                        break;
                    case "custInfoChange": // 身份信息变更
                        this.custInfoChangePage(params)
                        break;
                    case "contactInfoChange": // 联系方式变更
                        this.contactInfoChangePage(params)
                        break;
                    case "bankCardChange": // 银行卡变更
                        this.bankCardChangePage(params)
                        break;
                    case "repaymentDateChange": // 还款日变更
                        this.repaymentDateChangePage(params)
                        break;
                    case "assetsChange": // 资产信息变更
                        this.assetsChangePage(params)
                        break;
                    case "reprintContract": // 合同重出
                        this.reprintContractPage(params)
                        break;
                    case "overpayment": // 溢缴款退款
                        this.overpaymentPage(params)
                        break;
                    case "delayApply": // 延期申请
                        this.delayApplyPage(params)
                        break;
                    case "collectionRevoke": // 收款撤销
                        this.revokeHandlePage(params)
                        break;
                    case "exemptTypes": // 罚息豁免
                        this.exemptTypesPage(params)
                        break;
                    case "costExemptBill": // 费用豁免单
                        this.costExemptBillPage(params)
                        break;

                }
            },
            cancelContractPage(params) {
                params.isReadOnly = true;
                params.editFlag = true;
                params.type = 'read';
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/contract-cancellation/contract-cancellation-detial/index",
                    "合同取消详情",
                    "ios-add",
                    params,
                    "log-contract-cancellation-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            advanceSettlePage(params) {
                params.isReadOnly = true;
                this.afs.newTab(
                    this,
                    'projects/basic/pages/contract/clearance/apply-settle',
                    '提前还款申请',
                    'ios-add',
                    params,
                    'log-clearance-apply-' + this.pageNo,
                    [],
                    true
                );
            },
            extensionPage(params) {
            },
            insurancePage(params) {
                params.editFlag = true;
                params.readOnly = 'read';
                params.isReadOnly = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/insurance/insuranceInfoView",
                    "保险业务详情",
                    "ios-add",
                    params,
                    "log-contract-insurance-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            corporateTransferPage(v){
                let params={};
                params.modalTitle = "案件详情";
                params.dealModel = false;
                params.editModel = false;
                params.viewModel = true;
                params.caseNo = v.caseNo;
                params.contractNo = v.contractNo;
                params.caseType = v.caseType;
                params.prepaymentApplyId =  v.prepaymentApplyId;
                params.id = v.id;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/corporate/index",
                    "对公收款详情",
                    "ios-add",
                    params,
                    "corporate-detial-" + v.contractNo,
                    [],
                    true
                );
            },
            custInfoChangePage(params) {
                params.readOnly = true;
                params.isReadOnly = true;
                this.modal = false;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/post-loan-info-change/change-identity-detial/index",
                    "身份信息变更详情",
                    "ios-add",
                    params,
                    "log-change-identity-detail-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            contactInfoChangePage(params) {
                params.readOnly = true;
                params.isReadOnly = true;
                this.modal = false;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/post-loan-info-change/change-contact-detial/index",
                    "联系方式变更详情",
                    "ios-add",
                    params,
                    "log-change-contact-detail-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            bankCardChangePage(params) {
                params.readOnly = true;
                params.isReadOnly = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/post-loan-info-change/change-bank-card-detial/index",
                    "银行卡变更详情",
                    "ios-add",
                    params,
                    "log-change-bank-card-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            repaymentDateChangePage(params) {
                params.readOnly = true;
                params.isReadOnly = true;
                this.modal = false;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/post-loan-info-change/change-repayment-date-detial/index",
                    "还款日变更详情",
                    "ios-add",
                    params,
                    "log-change-repayment-date-detail-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            assetsChangePage(params) {
            },
            reprintContractPage(params) {
                params.isReadOnly = true;
                params.type = 'read';
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/contract-reissue/contract-reissue-detial/index",
                    "合同重出信息填写",
                    "ios-add",
                    params,
                    "log-contract-reissue-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            overpaymentPage(params) {
                params.readOnly = true;
                params.isReadOnly = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/contract-close/contract-close-detial",
                    "合同关闭详情",
                    "ios-add",
                    params,
                    "log-contract-close-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            delayApplyPage(params) {

            },
            revokeHandlePage(params) {
                params.type = "read";
                params.readOnly = true;
                params.editFlag = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/revoke-collection/revoke-collection-detial/index",
                    "收款撤销",
                    "ios-add",
                    params,
                    "revoke-collection-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            exemptTypesPage(params) {
                params.readOnly = "read";
                params.editFlag = false;
                params.isReadOnly = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/fee-waiver/penalty-exempt-detial/index",
                    "豁免罚息详情",
                    "ios-add",
                    params,
                    "penalty-exempt-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            costExemptBillPage(params) {
                params.readOnly = true;
                params.isReadOnly = true;
                this.afs.newTab(
                    this,
                    "projects/basic/pages/contract/fee-waiver/cost-exempt-bill-detial/index",
                    "费用豁免单详情",
                    "ios-add",
                    params,
                    "cost-exempt-bill-detial-" + this.pageNo,
                    [],
                    true
                );
                this.pageNo += 1;
            },
            back() {
                //关闭页面
                this.afs.closeTab(this);
            },
            showSpin() {
                this.spinShow = true;
            },
            closeSpin() {
                this.spinShow = false;
            },
            changChildrenData(refDom, name, value) {
                console.log(this.$refs[refDom], "this.$refs[name]");
                if (this.$refs[refDom]) {
                    this.$refs[refDom][name] = value;
                }
            }
        }
    };
</script>
<style lang="less">
    @import "../../../../../styles/common/form.less";
</style>
